//
//  DetailCell.m
//  敢唆嘛!
//
//  Created by lanou on 15/11/24.
//  Copyright © 2015年 zms. All rights reserved.
//

#import "DetailCell.h"
#import "Device.h"
@implementation DetailCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.wenzhangLabel = [[UILabel alloc]initWithFrame:CGRectMake(space, space, KSWidth-space*2, KSWidth/2)];
        self.wenzhangLabel.font = [UIFont systemFontOfSize:12];
        self.wenzhangLabel.numberOfLines = 0;
//        self.wenzhangLabel.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:self.wenzhangLabel];
        
        
    }
    return self;
}

- (void)setHomeModel:(HomeModel *)model
{
    self.wenzhangLabel.text = model.info;
//    // 超过1行设置行间距
//    if (self.wenzhangLabel.frame.size.height > KSWidth / 22)
//    {
//        [self setAttributedString:self.wenzhangLabel line:5];
//    }
    CGRect bounds = [model.info boundingRectWithSize:CGSizeMake(KSWidth-space*2, 1000000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:12] forKey:NSFontAttributeName] context:nil];
    self.wenzhangLabel.frame = CGRectMake(space, space, KSWidth-space*2, bounds.size.height);
}

- (void)setRealityModel:(RealityModel *)model
{
    self.wenzhangLabel.text = model.info;
//    // 超过1行设置行间距
//    if (self.wenzhangLabel.frame.size.height > KSWidth / 22)
//    {
//        [self setAttributedString:self.wenzhangLabel line:5];
//    }
    CGRect bounds = [model.info boundingRectWithSize:CGSizeMake(KSWidth-space*2, 1000000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:12] forKey:NSFontAttributeName] context:nil];
    self.wenzhangLabel.frame = CGRectMake(space, space, KSWidth-space*2, bounds.size.height);
}

//动态返回cell高度
+(CGFloat)heightForHomeCell:(HomeModel *)model
{
     CGRect bounds = [model.info boundingRectWithSize:CGSizeMake(KSWidth-space*2, 1000000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:12] forKey:NSFontAttributeName] context:nil];
    return bounds.size.height + space * 2;
}

+(CGFloat)heightForRealityCell:(RealityModel *)model
{
    CGRect bounds = [model.info boundingRectWithSize:CGSizeMake(KSWidth-space*2, 1000000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:12] forKey:NSFontAttributeName] context:nil];
    return bounds.size.height + space * 2;
}

// 设置行间距
- (void)setAttributedString:(UILabel *)label line:(CGFloat)line
{
    //        设置行间距
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:label.text];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:line];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, label.text.length)];
    label.attributedText = attributedString;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
